package com.markgrand.structuredSql

import scala.collection.mutable.StringBuilder

/**
 * Generate a * for a select list.  The * may be qualified by a table name or alias.
 * 
 * @param tableName
 *      The name or alias of the table that this column is part of.
 * @author Mark Grand
 */
class SelectStar protected (val tableName:Option[String]) extends SelectValueAppender with SQLIdentifier {
  def append(builder: StringBuilder): Unit = tableName match {
    case Some(table) =>
      appendIdentifier(table, builder)
      builder.append(".*")
    case None =>
      builder.append("*")
  }
}

object SelectStar {
  def apply() = new SelectStar(None)
  
  def apply(tableNameOrAlias: String) = new SelectStar(Some(tableNameOrAlias))
}
